package com.datamation.swadeshi.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.datamation.swadeshi.R;
import com.datamation.swadeshi.model.Debtor;
import com.datamation.swadeshi.view.MainActivity;


public class CustomerAdapter extends ArrayAdapter<Debtor> {
	Context context;
	ArrayList<Debtor> list;
	
	public CustomerAdapter(Context context, ArrayList<Debtor> list){
		
		super(context, R.layout.row_customer_listview, list);
		this.context = context;
		this.list = list;		
	}
	
	
	@Override
	public View getView(final int position, final View convertView, final ViewGroup parent) {
		
		LayoutInflater inflater = null;
		View row = null;
		
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		row = inflater.inflate(R.layout.row_customer_listview, parent, false);
		
		LinearLayout layout = (LinearLayout) row.findViewById(R.id.linearLayout);
		TextView code = (TextView) row.findViewById(R.id.debCode);
		TextView name = (TextView) row.findViewById(R.id.debName);
		TextView address = (TextView) row.findViewById(R.id.debAddress);
	
//		try {
//		MainActivity activity = (MainActivity) context;
//		if(activity.selectedDebtor != null){
//			if(list.get(position).getFDEBTOR_CODE().toString().equals(activity.selectedDebtor.getFDEBTOR_CODE().toString())){
//				Log.v("LOG", activity.selectedDebtor.getFDEBTOR_CODE());
//				layout.setBackgroundColor(context.getResources().getColor(R.color.selected));
//				activity.cusPosition=position;
//			}
//		}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
		
		code.setText(list.get(position).getFDEBTOR_CODE());
		name.setText(list.get(position).getFDEBTOR_NAME());
		address.setText(list.get(position).getFDEBTOR_ADD1()+" "+list.get(position).getFDEBTOR_ADD2()+" "+
						list.get(position).getFDEBTOR_ADD3());
		Log.v("Position Custmer", position+"");		
		return row;
	}
}
